﻿using Studio77.GuessTheWordsWin8.Core;
using Studio77.GuessTheWordsWin8.Entities;
using Studio77.GuessTheWordsWin8.Utils;
using Studio77.GuessTheWordsWin8.Views;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Data.Xml.Dom;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.System;
using Windows.UI.Notifications;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “基本页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234237 上有介绍

namespace Studio77.GuessTheWordsWin8.Pages
{
    /// <summary>
    /// 基本页，提供大多数应用程序通用的特性。
    /// </summary>
    public sealed partial class GamePage : Studio77.GuessTheWordsWin8.Common.LayoutAwarePage
    {
        private const int CHARBLOCK_SIZE = 61;

        public static GamePage GamePageInstance;

        CharacterBlock[,] blocks;
        CharacterBlock selectedBlock = null;
        List<CharacterBlock> senseBlocks_horizon;
        List<CharacterBlock> senseBlocks_vertical;
        int currentRow { get; set; }
        int currentColumn { get; set; }
        bool isPreviousRight = true;
        List<String> scoreStrs = new List<string>();
        Random r = new Random(DateTime.Now.Millisecond);

        bool isPause = false;

        object pauseSyncObj = new object();

        public GamePage()
        {
            this.InitializeComponent();
            GamePageInstance = this;
            DisplayProperties.AutoRotationPreferences = DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;
            scoreStrs.Add("再接再厉！");
            scoreStrs.Add("厉害！");
            scoreStrs.Add("牛！");
            scoreStrs.Add("加油！");
            scoreStrs.Add("不错哦！");
            scoreStrs.Add("你好厉害啊！");
            scoreStrs.Add("对你崇拜地五体投地！");
            scoreStrs.Add("快去参加知识问答类节目吧，你是冠军！");
            scoreStrs.Add("答对了！你确定你没有用百度！？");
            scoreStrs.Add("可恶，难不倒你啊");
            scoreStrs.Add("要不要这么准，看好你哦");
            scoreStrs.Add("帅哥美女，你又答对了");
            this.KeyDown += GamePage_KeyDown;
        }

        /// <summary>
        /// 使用在导航过程中传递的内容填充页。在从以前的会话
        /// 重新创建页时，也会提供任何已保存状态。
        /// </summary>
        /// <param name="navigationParameter">最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, Object)"/> 的参数值。
        /// </param>
        /// <param name="pageState">此页在以前会话期间保留的状态
        /// 字典。首次访问页面时为 null。</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            //JiuYouSDK.Start();//调用方法,显示广告
        }

        /// <summary>
        /// 保留与此页关联的状态，以防挂起应用程序或
        /// 从导航缓存中放弃此页。值必须符合
        /// <see cref="SuspensionManager.SessionState"/> 的序列化要求。
        /// </summary>
        /// <param name="pageState">要使用可序列化状态填充的空字典。</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            //保存游戏进度
            StageManager.Instance.saveStageDatas();
        }

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            InitGame();
            if (!StageManager.Instance.IsShowedGuide)
            {
                MessageDialog msg = new MessageDialog("这是您第一次进行游戏，是否显示游戏教程？也可以在游戏页菜单栏中找到教程。");
                msg.Commands.Add(new UICommand("好的", (command) =>
                {
                    StageManager.Instance.IsShowedGuide = true;
                    this.Frame.Navigate(typeof(GuidePage));
                }));
                msg.Commands.Add(new UICommand("不用了，谢谢！", (command) =>
                {
                    StageManager.Instance.IsShowedGuide = true;
                }));
                await msg.ShowAsync();
            }
        }

        private void InitGame()
        {
            this.cvsBlocks.Tapped += cvsBlocks_Tapped;
            InitStage(StageManager.Instance.LastStage);
            this.btnLamp.Content = StageManager.Instance.LampCount.ToString();
        }

        void cvsBlocks_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Point point = e.GetPosition(this.cvsBlocks);
            int column = (int)point.X / CHARBLOCK_SIZE;
            int row = (int)point.Y / CHARBLOCK_SIZE;
            changeSelectBlock(column, row, 0);
            //重设焦点
            this.Focus(Windows.UI.Xaml.FocusState.Keyboard);
        }

        /// <summary>
        /// 修改选中
        /// </summary>
        /// <param name="column"></param>
        /// <param name="row"></param>
        /// <param name="type">0-点击 1-向下运动 2-向右运动</param>
        private void changeSelectBlock(int column, int row, int type)
        {
            if (row >= 0 && row < 10 && column >= 0 && column < 10)
            {

                if (blocks[row, column].CurrentType != BlockType.NoChar)
                {
                    if (selectedBlock != null)
                    {
                        selectedBlock.changeBackgroundType(0);
                    }

                    blocks[row, column].changeBackgroundType(2);
                    selectedBlock = blocks[row, column];

                    currentRow = row;
                    currentColumn = column;

                    findSenseBlocks(row, column);

                    // show tip
                    setTip(selectedBlock.HorizontalTip,
                            selectedBlock.VerticalTip);
                }
                else
                {
                    if (type == 0)
                    {
                        clearSelection();
                    }
                    else if (type == 1)
                    {
                        MoveDown();
                    }
                    else if (type == 2)
                    {
                        MoveUp();
                    }
                }
                isPreviousRight = true;
            }
        }

        /// <summary>
        /// 查找感应块
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        private void findSenseBlocks(int row, int column)
        {

            // 恢复状态
            foreach (CharacterBlock block in senseBlocks_horizon)
            {
                if (block.CurrentType != BlockType.Selected)
                {
                    block.changeBackgroundType(BlockType.Normal);
                }
            }

            foreach (CharacterBlock block in senseBlocks_vertical)
            {
                if (block.CurrentType != BlockType.Selected)
                {
                    block.changeBackgroundType(BlockType.Normal);
                }
            }

            // 清空
            senseBlocks_horizon.Clear();
            senseBlocks_vertical.Clear();

            // 横向向左
            if (column > 0)
            {
                for (int i = column - 1; i >= 0; i--)
                {
                    if (blocks[row, i].CurrentType == BlockType.NoChar)
                    {
                        break;
                    }
                    senseBlocks_horizon.Add(blocks[row, i]);
                }
            }
            // 横向向右
            if (column < 10 - 1)
            {
                for (int i = column + 1; i < 10; i++)
                {
                    if (blocks[row, i].CurrentType == BlockType.NoChar)
                    {
                        break;
                    }
                    senseBlocks_horizon.Add(blocks[row, i]);
                }
            }
            // 竖向向上
            if (row > 0)
            {
                for (int i = row - 1; i >= 0; i--)
                {
                    if (blocks[i, column].CurrentType == BlockType.NoChar)
                    {
                        break;
                    }
                    senseBlocks_vertical.Add(blocks[i, column]);
                }
            }
            // 竖向向下
            if (row < 10 - 1)
            {
                for (int i = row + 1; i < 10; i++)
                {
                    if (blocks[i, column].CurrentType == BlockType.NoChar)
                    {
                        break;
                    }
                    senseBlocks_vertical.Add(blocks[i, column]);
                }
            }

            // 切换显示状态
            foreach (CharacterBlock block in senseBlocks_horizon)
            {
                block.changeBackgroundType(BlockType.SenseHorizon);
            }
            foreach (CharacterBlock block in senseBlocks_vertical)
            {
                block.changeBackgroundType(BlockType.SenseVertical);
            }
        }

        /// <summary>
        /// 清除选中状态
        /// </summary>
        private void clearSelection()
        {
            // 选中了nochar block, 清楚select以及sense,恢复提示
            if (selectedBlock != null)
            {
                selectedBlock.changeBackgroundType(0);
                selectedBlock = null;
            }
            foreach (CharacterBlock block in senseBlocks_horizon)
            {
                block.changeBackgroundType(BlockType.Normal);
            }
            foreach (CharacterBlock block in senseBlocks_vertical)
            {
                block.changeBackgroundType(BlockType.Normal);
            }
            setToDefaultTip();
        }

        private void setToDefaultTip()
        {
            txtDefaultTip.Visibility = Windows.UI.Xaml.Visibility.Visible;
            txtHorizonTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            txtVerticalTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }

        private void setTip(string hTip, string vTip)
        {
            txtDefaultTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if (!string.IsNullOrEmpty(hTip))
            {
                txtHorizonTip.Text = "横:" + hTip;
                txtHorizonTip.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                txtHorizonTip.Text = string.Empty;
                txtHorizonTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            if (!string.IsNullOrEmpty(vTip))
            {
                txtVerticalTip.Text = "竖:" + vTip;
                txtVerticalTip.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                txtVerticalTip.Text = string.Empty;
                txtVerticalTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }

        private void InitStage(int stageIndex)
        {
            this.txtStageInfo.Text = "关卡-" + stageIndex;
            isPause = false;
            blocks = new CharacterBlock[10, 10];
            selectedBlock = null;
            senseBlocks_horizon = new List<CharacterBlock>();
            senseBlocks_vertical = new List<CharacterBlock>();

            this.cvsBlocks.Children.Clear();

            currentRow = -1;
            currentColumn = -1;

            // 创建对象矩阵
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    CharacterBlock block = new CharacterBlock();

                    Canvas.SetLeft(block, j * CHARBLOCK_SIZE);
                    Canvas.SetTop(block, i * CHARBLOCK_SIZE);

                    // 初始化均为不可用状态
                    block.changeBackgroundType(BlockType.NoChar);
                    block.Row = i;
                    block.Column = j;
                    blocks[i, j] = block;
                    cvsBlocks.Children.Add(block);
                }
            }
            try
            {
                setCharMatrix(stageIndex);
            }
            catch
            {

            }
            setToDefaultTip();

        }

        /// <summary>
        /// 根据数据源设置矩阵状态
        /// </summary>
        /// <param name="index"></param>
        private async void setCharMatrix(int index)
        {
            // 读取矩阵数据，并设置矩阵状态
            MapInfo mapInfo;
            if (StageManager.Instance.mapInfos.ContainsKey(index))
            {
                mapInfo = StageManager.Instance.mapInfos[index];
            }
            else
            {
                mapInfo = await WordMapLoader.LoadMap(index);
            }

            if (mapInfo != null)
            {

                StageData stageData;
                if (StageManager.Instance.stageDatas.ContainsKey(index))
                {
                    stageData = StageManager.Instance.stageDatas[index];
                }
                else
                {
                    stageData = new StageData();
                    StageManager.Instance.stageDatas[index] = stageData;
                }


                foreach (CharacterLocationInfo location in mapInfo.charLocationList)
                {

                    CharacterBlock aimBlock = blocks[location.row, location.column];
                    aimBlock.changeBackgroundType(BlockType.Normal);
                    if (location.orientationWordIndex >= 0 && mapInfo.wordList.Count > location.orientationWordIndex)
                    {
                        // 横向有数据
                        WordInfo word = mapInfo.wordList[location.orientationWordIndex];

                        try
                        {
                            aimBlock.setAimHorizon(word.pinyin.Substring(location.orientationCharIndex, 1), word.content.Substring(location.orientationCharIndex, 1));

                            // 设置Tip
                            aimBlock.HorizontalTip = word.tip;
                            aimBlock.HorizonWordIndex = location.orientationWordIndex;
                        }
                        catch
                        { }
                    }
                    if (location.verticalWordIndex >= 0 && mapInfo.wordList.Count > location.verticalWordIndex)
                    {

                        // 竖向
                        WordInfo word = mapInfo.wordList[location.verticalWordIndex];
                        try
                        {

                            aimBlock.setAimVertical(word.pinyin.Substring(location.verticalCharIndex, 1), word.content.Substring(location.verticalCharIndex, 1));

                            // 设置Tip
                            aimBlock.VerticalTip = word.tip;
                            aimBlock.VerticalWordIndex = location.orientationWordIndex;
                        }
                        catch
                        { }
                    }
                    // 根据历史完成情况进行设置
                    if (stageData != null)
                    {
                        int blockKey = location.row * 10 + location.column;
                        if (stageData.CharInfoList.ContainsKey(blockKey))
                        {
                            MatrixCharInfo info = stageData.CharInfoList[blockKey];
                            if (info != null)
                            {
                                if (info.IsComplete)
                                {
                                    aimBlock.setComplete();
                                }
                                else
                                {
                                    aimBlock.setShowChar(info.CharStr);
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 按下按钮之后的处理
        /// </summary>
        /// <param name="keyStr"></param>
        public void touchKey(String keyStr)
        {
            if (isPause)
            {
                return;
            }
            if (selectedBlock != null)
            {
                if (!selectedBlock.IsCompleted)
                {

                    // 首先判断是否是lamp
                    if (keyStr == "lamp")
                    {
                        if (StageManager.Instance.LampCount > 0)
                        {
                            selectedBlock.setComplete();
                            // 减少灯泡数量
                            StageManager.Instance.LampCount = StageManager.Instance.LampCount - 1;
                            this.btnLamp.Content = StageManager.Instance.LampCount.ToString();
                        }
                        else
                        {
                            // 没有可用的灯泡了，提示用户可以点击广告或者进入积分墙获取灯泡
                            //ShowToast("亲，没有提示灯泡喽！每次解锁3个关卡可以赠送6个哦，加油！");
                            ShowToast(string.Empty, "没有提示灯泡喽！可以试试别的看，有机会获得提示哦。");
                        }
                    }
                    else
                    {
                        selectedBlock.setShowChar(keyStr);
                    }

                    // 判断词条是否完全匹配，显示完整词条数据
                    processJudgeComplete(senseBlocks_horizon, true);
                    processJudgeComplete(senseBlocks_vertical, false);
                }
            }
            moveToNextSelectedBlock();
        }

        private object saveSyncObj = new object();

        private void processJudgeComplete(List<CharacterBlock> senseList, bool isHorizon)
        {
            lock (saveSyncObj)
            {

                if (senseList.Count > 0)
                {
                    bool isSuccess = true;
                    foreach (CharacterBlock block in senseList)
                    {
                        if (!block.isCorrectPy())
                        {
                            isSuccess = false;
                            break;
                        }
                    }

                    // 判断当前点
                    if (isSuccess && selectedBlock.isCorrectPy())
                    {
                        // 成功
                        selectedBlock.setComplete();
                        foreach (CharacterBlock block in senseList)
                        {
                            block.setComplete();
                        }
                        StageData sd = StageManager.Instance.getCurrentStageData();
                        sd.ComplateCount = sd.ComplateCount + 1;

                        if (sd.ComplateCount >= StageManager.Instance.mapInfos[StageManager.Instance.LastStage].wordsCount)
                        {
                            ShowToast("恭喜你完成了本关卡，送您5个提示灯泡！要继续努力哦");
                            StageManager.Instance.LampCount = StageManager.Instance.LampCount + 5;
                            this.btnLamp.Content = StageManager.Instance.LampCount.ToString();
                        }

                        // 得分
                        addScore(sd);

                        //ShowTip
                        ShowScoreTip();

                        //判断能否解锁下一个关卡
                        UnlockNextStage(sd);

                        //异步保存数据
                        StageManager.Instance.saveStageDatas();
                    }
                }
            }
        }

        /// <summary>
        /// 解锁下一个关卡
        /// </summary>
        private void UnlockNextStage(StageData sd)
        {
            //完成10个词条，解锁下个关卡
            if (sd.ComplateCount >= 10)
            {
                if (!StageManager.Instance.stageDatas.ContainsKey(StageManager.Instance.LastStage + 1))
                {
                    //提示解锁了新关卡
                    ShowToast("恭喜", "凭借您的聪明才智，您解锁了全新的关卡！");
                    StageManager.Instance.stageDatas.Add(StageManager.Instance.LastStage + 1, new StageData());
                }
            }
        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        /// <param name="message"></param>
        public static void ShowToast(String message)
        {
            ShowToast("提示", message);
        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        public static void ShowToast(String title, String message)
        {
            string toastStr = "<toast duration='short' launch='Page1'>"
                               + "<visual version='1'>"
                               + "<binding template='ToastText02'>"
                               + "<text id='1'>" + title + "</text>"
                               + "<text id='2'>" + message + "</text>"
                               + "</binding>"
                               + "</visual>"
                               + "</toast>";
            XmlDocument toastXml = new XmlDocument();
            toastXml.LoadXml(toastStr);
            ToastNotification toastNotification = new ToastNotification(toastXml);
            ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
        }

        /// <summary>
        /// 显示得分ScoreTip
        /// </summary>
        private void ShowScoreTip()
        {
            //TODO lc 显示激励语句及奖品信息
            //8分之一的机会得到一个提示道具
            int intLamp = r.Next(8);
            if (intLamp == 7)
            {
                //送一次提示
                ShowToast("新的提示机会", "恭喜你获得一次提示机会");
                StageManager.Instance.LampCount = StageManager.Instance.LampCount + 1;
                this.btnLamp.Content = StageManager.Instance.LampCount.ToString();
            }
            else
            {
                ShowToast(string.Empty, scoreStrs[r.Next(scoreStrs.Count)]);
            }
        }


        private void moveToNextSelectedBlock()
        {
            try
            {
                // 根据上一次的移动动作，进行向下或者向右
                if (isPreviousRight)
                {
                    // 将选择移动至下个block，先向右，再向下
                    if (currentColumn < 9
                            && currentColumn >= 0
                            && currentRow >= 0 && currentRow < 10
                            && blocks[currentRow, currentColumn + 1].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn + 1, currentRow, 2);
                        isPreviousRight = true;
                    }
                    else if (currentRow < 9
                          && currentRow >= 0
                          && currentColumn >= 0 && currentColumn < 10
                          && blocks[currentRow + 1, currentColumn].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn, currentRow + 1, 1);
                        isPreviousRight = false;
                    }
                    else
                    {
                        //clearSelection();
                    }
                }
                else
                {
                    // 将选择移动至下个block，先向下，再向右
                    if (currentRow < 9
                            && currentRow >= 0
                            && currentColumn >= 0 && currentColumn < 10
                            && blocks[currentRow + 1, currentColumn].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn, currentRow + 1, 1);
                        isPreviousRight = false;
                    }
                    else if (currentColumn < 9
                          && currentColumn >= 0
                          && currentRow >= 0 && currentRow < 10
                          && blocks[currentRow, currentColumn + 1].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn + 1, currentRow, 2);
                        isPreviousRight = true;
                    }
                    else
                    {
                        //clearSelection();
                    }
                }
            }
            catch
            { }
        }

        private void addScore(StageData sd)
        {
            if (sd.TotalSeconds <= 200)
            {
                sd.Score += 800;
            }
            else if (sd.TotalSeconds <= 400)
            {
                sd.Score += +500;
            }
            else if (sd.TotalSeconds <= 600)
            {
                sd.Score += +200;
            }
            else
            {
                sd.Score += 100;
            }
        }

        private void btnPauseClearStageData_Click(object sender, RoutedEventArgs e)
        {
            //if (MessageBox.Show("重玩将清空本关卡的记录，您确定吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            //{
            //    StageManager.Instance.ClearCurrentStageDate();
            //    this.bdrPause.Visibility = System.Windows.Visibility.Collapsed;
            //    InitStage(StageManager.Instance.LastStage);
            //}
        }

        private void btnGoback_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.GoBack(this, e);
        }

        private void btnLamp_Click(object sender, RoutedEventArgs e)
        {
            touchKey("lamp");
        }

        void GamePage_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key >= VirtualKey.A && e.Key <= VirtualKey.Z)
            {
                touchKey(e.Key.ToString().ToUpper());
            }
            else if (e.Key == VirtualKey.Left)
            {
                MoveLeft();
            }
            else if (e.Key == VirtualKey.Right)
            {
                MoveRight();
            }
            else if (e.Key == VirtualKey.Up)
            {
                MoveUp();
            }
            else if (e.Key == VirtualKey.Down)
            {
                MoveDown();
            }
        }

        private void MoveUp()
        {
            if (selectedBlock != null)
            {
                for (int i = currentRow - 1; i >= 0; i--)
                {
                    if (blocks[i, currentColumn].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn, i, 0);
                        break;
                    }
                }
            }
        }

        private void MoveLeft()
        {
            if (selectedBlock != null)
            {
                for (int i = currentColumn - 1; i >= 0; i--)
                {
                    if (blocks[currentRow, i].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(i, currentRow, 0);
                        break;
                    }
                }
            }
        }

        private void MoveDown()
        {
            if (selectedBlock != null)
            {
                for (int i = currentRow + 1; i < 10; i++)
                {
                    if (blocks[i, currentColumn].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(currentColumn, i, 0);
                        break;
                    }
                }
            }
        }

        private void MoveRight()
        {
            if (selectedBlock != null)
            {
                for (int i = currentColumn + 1; i < 10; i++)
                {
                    if (blocks[currentRow, i].CurrentType != BlockType.NoChar)
                    {
                        changeSelectBlock(i, currentRow, 0);
                        break;
                    }
                }
            }
        }

        protected override void OnLostFocus(RoutedEventArgs e)
        {
            base.OnLostFocus(e);
        }

        private async void btnClearStageData_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            MessageDialog msg = new MessageDialog("将清空本关卡的游戏记录，您确定吗？");
            msg.Commands.Add(new UICommand("确定", (command) =>
            {
                StageManager.Instance.ClearCurrentStageDate();
                InitStage(StageManager.Instance.LastStage);
            }));
            msg.Commands.Add(new UICommand("取消", (command) =>
            {
            }));
            await msg.ShowAsync();
        }

        private void btnGuide_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(GuidePage));
        }

        private async void MokaAd_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Uri uri = new Uri("http://bj.adserve.ifreeteam.com:9090/advertise/ad/receive.json?id=903ce9225f");
            await Launcher.LaunchUriAsync(uri);
        }
    }
}
